<?php
namespace Common\Model;
use Common\Model\BaseModel;
use Think\Model;

/**
 * Class NavPrivModel
 * @package Common\Model
 * 栏目权限模型
 */
class NavPrivModel extends BaseModel {
    public $pix = "";
    public $fieldsStr = '*';
    public $orderStr = 'id asc';

    public function add_new_one($role, $nav, $opr){
        $map['role'] = array('eq', $role);
        $map['nav'] = array('eq', $nav);
        $map['opr'] = array('eq', $opr);
        $one = $this->where($map)->find();
        if(!$one){
            $data['role'] = $role;
            $data['nav'] = $nav;
            $data['opr'] = $opr;
            return $this->add($data);
        }
        return false;
    }

    public function del_new_one($role, $nav, $opr){
        $map['role'] = array('eq', $role);
        $map['nav'] = array('eq', $nav);
        $map['opr'] = array('eq', $opr);
        return $this->where($map)->delete();
    }

    public function query_once_to_array($role){
        $array = array();
        $map['role'] = array('eq', $role);
        $list = $this->where($map)->select();
        foreach($list as $priv){
            $array[] = $priv['nav'].','.$priv['opr'];
        }
        return $array;
    }

    public function checked_priv($role, $nav, $opr){
        $map['role'] = array('eq', $role);
        $map['nav'] = array('eq', $nav);
        $map['opr'] = array('eq', $opr);
        $one = $this->where($map)->find();
        return $one?true:false;
    }

}